<?php
namespace Models\Model;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\Db\Sql;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;
use Zend\Paginator\Paginator;
use Zend\Db\Sql\Predicate;
use Zend\Db\Sql\Expression;
class AdminSettingsTable
{
    protected $tableGateway;
	protected $select;
    public function __construct(TableGateway $tableGateway)
    {
        $this->tableGateway = $tableGateway;
		$this->select = new Select();
    }
	//Registration
	public function saveAdminSettings($admin){
		$data = array(
			'win_message' 				=> $admin['win_message'], 
			'win_message_arabic' 		=> $admin['win_message_arabic'], 
			'win_logo'  	 			=> $admin['win_logo'],  	
			'reg_image' 	 			=> $admin['reg_image'],  
			'numberof_failure_attemts'	=> $admin['numberof_failure_attemts'], 							
			'numberof_chance_per_day'	=> $admin['numberof_chance_per_day'], 							
			'numberof_success_per_day'	=> $admin['numberof_success_per_day'], 							
			'life_time_wins'	 		=> $admin['life_time_wins'], 							
			'cretaed_date'	 			=> date('Y-m-d H:i:s'), 							
			'update_date'	 			=> date('Y-m-d H:i:s'), 							
			'status'	 				=> 1, 							
		);	
		$insertresult=$this->tableGateway->insert($data);	
		return $this->tableGateway->lastInsertValue;
    }	
	
	public function updateAdminSettings($id,$admin,$regimage,$logoimage){
		if($logoimage!=""){
			$datalogo = array(
				'win_logo'  	 			=> $logoimage,  				
			);		
			$update1=$this->tableGateway->update($datalogo, array('win_id' => $id));
		}
		if($regimage!=""){
			$datareg = array(
				'reg_image' 	 			=> $regimage,    
			);	
			$update2=$this->tableGateway->update($datareg, array('win_id' => $id));
		}
		$data = array(
			'win_message' 				=> $admin['win_message'], 
			'win_message_arabic' 		=> $admin['win_message_arabic'], 
			'numberof_failure_attemts'	=> $admin['numberof_failure_attemts'], 							
			'numberof_chance_per_day'	=> $admin['numberof_chance_per_day'], 							
			'numberof_success_per_day'	=> $admin['numberof_success_per_day'], 							
			'life_time_wins'	 		=> $admin['life_time_wins'], 							
			'cretaed_date'	 			=> date('Y-m-d H:i:s'), 							
			'update_date'	 			=> date('Y-m-d H:i:s'), 							
			'status'	 				=> 1, 							
		);	
		$updateuserid=$this->tableGateway->update($data, array('win_id' => $id));
	   return $updateuserid;
    }	
	
	public function getAllSettings(){	
		$select = $this->tableGateway->getSql()->select();
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
	public function checkAdmindata($data){	
		$select = $this->tableGateway->getSql()->select();
		$select= $this->where->
		$resultSet = $this->tableGateway->selectWith($select);
		return $resultSet;
	}
}